package com.example.wecomservice.controller.web;

import com.example.wecomservice.utils.SignatureUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Jamin
 * @Date 2023/2/3 16:07
 */
@RestController
@RequestMapping("/web/weCom")
public class WeComController {

    @ApiOperation("企业微信自动登录")
    @GetMapping("/autoLogin")
    public String autoLogin(HttpServletRequest request){
        String openUserId = request.getParameter("openUserId");
        String authCorpId = request.getParameter("authCorpId");
        String timestamp = request.getParameter("timestamp");
        String signature = request.getParameter("signature");
        Integer signatureRet = SignatureUtil.verifySignature(authCorpId + "_" + openUserId + "_" + timestamp, timestamp, signature, 1000*60*5L);
        if (signatureRet==0){
            return "登录成功";
        }
        return "登录失败";
    }
}
